package  
{
	import org.flixel.FlxG;
	import org.flixel.FlxPoint;
	/**
	 * ...
	 * @author morgan
	 */
	public class Throwable extends ReflectionSprite
	{
		
		public var airStopSpeed:Number = 20;
		public var groundStopSpeed:Number = 300;
		public var bounciness:Number = 0.3;
		public var touchGroundFriction:Number = 0.5;
		
		public var lastVelocity:FlxPoint = new FlxPoint(0,0);
		
		public function Throwable(x:int, y:int, scene:GameScene, image:Class = null) 
		{
			super(x, y, scene, image);
			mass = 1.0;
			acceleration.y = 130;
		}
		
		override public function update():void 
		{
			super.update();
			
			if (justTouched(LEFT)) 
				velocity.x = Math.abs(lastVelocity.x) * bounciness;
			
			if (justTouched(RIGHT))
				velocity.x = -Math.abs(lastVelocity.x) * bounciness;
				
			if (justTouched(DOWN))
			{
				velocity.y = -Math.abs(lastVelocity.y) * bounciness;
				velocity.x *= touchGroundFriction;
			}
				
			if (justTouched(UP))
				velocity.y = Math.abs(lastVelocity.y) * bounciness;				
			
			
			var sign:Number = velocity.x > 0 ? 1 : -1;
			velocity.x -= Math.min(sign * velocity.x, (isTouching(FLOOR) ? groundStopSpeed : airStopSpeed) * FlxG.elapsed) * sign;			
			
			lastVelocity.x = velocity.x;
			lastVelocity.y = velocity.y;
		}
		
	}

}